module LINF_TOP (
   input                     LINF_RESET,
   input                     GTM_SYSCLK77,
   input                     GTM_SYSCLK155,
   input                     GTM_SYSCLK311,
   input                     GTM_LINF_REFCLK311_0,
   input                     GTM_LINF_REFCLK311_45,
   input                     GTM_LINF_REFCLK311_90,
   input                     GTM_LINF_REFCLK311_135,
   input                     GTM_LINF_REFCLK155,

   input[3:0]                GLBCF_LINF_MODE,

   input                     AFE_RXD_0,
   input                     AFE_RXD_1,
   input                     AFE_RXD_2,
   input                     AFE_RXD_3,

   output[7:0]               LINF_OUT_RXD_0,
   output                    LINF_OUT_RXDEN_0,
   output[7:0]               LINF_OUT_RXD_1,
   output                    LINF_OUT_RXDEN_1,
   output[7:0]               LINF_OUT_RXD_2,
   output                    LINF_OUT_RXDEN_2,
   output[7:0]               LINF_OUT_RXD_3,
   output                    LINF_OUT_RXDEN_3,


   output                    AFE_TXD_0,
   output                    AFE_TXD_1,
   output                    AFE_TXD_2,
   output                    AFE_TXD_3,

   input[7:0]                LINF_IN_TXD_0,
   input[7:0]                LINF_IN_TXD_1,
   input[7:0]                LINF_IN_TXD_2,
   input[7:0]                LINF_IN_TXD_3
   ) ;


wire[15:0]        OVSMP_DATA_0, OVSMP_DATA_1, OVSMP_DATA_2, OVSMP_DATA_3;

wire[7:0]         RCV_DATA_0, RCV_DATA_1, RCV_DATA_2, RCV_DATA_3;
wire              RCV_DATA_EN_0, RCV_DATA_EN_1, RCV_DATA_EN_2, RCV_DATA_EN_3;







/*LINF_PLL                                INST_LINF_PLL(
   .areset                              ( LINF_RESET ),
   .inclk0                              ( LINF_SYS_CLOCK155 ),
   .c0                                  ( RFCLK_CLOCK155 ),
   .c1                                  ( RFCLK_CLOCK311_0 ),
   .c2                                  ( RFCLK_CLOCK311_45 ),
   .c3                                  ( RFCLK_CLOCK311_90 ),
   .c4                                  ( RFCLK_CLOCK311_135 ),
   .locked                              (  )
   );*/





LINF_OVSAMPLE                           INST_LINF_OVSAMPLE_0(
   .LINF_RESET                          ( LINF_RESET ),

   .RFCLK_CLOCK311_0                    ( GTM_LINF_REFCLK311_0 ),
   .RFCLK_CLOCK311_45                   ( GTM_LINF_REFCLK311_45 ),
   .RFCLK_CLOCK311_90                   ( GTM_LINF_REFCLK311_90 ),
   .RFCLK_CLOCK311_135                  ( GTM_LINF_REFCLK311_135 ),
   .RFCLK_CLOCK155                      ( GTM_LINF_REFCLK155 ),

   .AFE_RXD                             ( AFE_RXD_0 ),

   .OVSMP_OUT_DATA                      ( OVSMP_DATA_0[15:0] )
   ) ;
LINF_OVSAMPLE                           INST_LINF_OVSAMPLE_1(
   .LINF_RESET                          ( LINF_RESET ),

   .RFCLK_CLOCK311_0                    ( GTM_LINF_REFCLK311_0 ),
   .RFCLK_CLOCK311_45                   ( GTM_LINF_REFCLK311_45 ),
   .RFCLK_CLOCK311_90                   ( GTM_LINF_REFCLK311_90 ),
   .RFCLK_CLOCK311_135                  ( GTM_LINF_REFCLK311_135 ),
   .RFCLK_CLOCK155                      ( GTM_LINF_REFCLK155 ),

   .AFE_RXD                             ( AFE_RXD_1 ),

   .OVSMP_OUT_DATA                      ( OVSMP_DATA_1[15:0] )
   ) ;
LINF_OVSAMPLE                           INST_LINF_OVSAMPLE_2(
   .LINF_RESET                          ( LINF_RESET ),

   .RFCLK_CLOCK311_0                    ( GTM_LINF_REFCLK311_0 ),
   .RFCLK_CLOCK311_45                   ( GTM_LINF_REFCLK311_45 ),
   .RFCLK_CLOCK311_90                   ( GTM_LINF_REFCLK311_90 ),
   .RFCLK_CLOCK311_135                  ( GTM_LINF_REFCLK311_135 ),
   .RFCLK_CLOCK155                      ( GTM_LINF_REFCLK155 ),

   .AFE_RXD                             ( AFE_RXD_2 ),

   .OVSMP_OUT_DATA                      ( OVSMP_DATA_2[15:0] )
   ) ;
LINF_OVSAMPLE                           INST_LINF_OVSAMPLE_3(
   .LINF_RESET                          ( LINF_RESET ),

   .RFCLK_CLOCK311_0                    ( GTM_LINF_REFCLK311_0 ),
   .RFCLK_CLOCK311_45                   ( GTM_LINF_REFCLK311_45 ),
   .RFCLK_CLOCK311_90                   ( GTM_LINF_REFCLK311_90 ),
   .RFCLK_CLOCK311_135                  ( GTM_LINF_REFCLK311_135 ),
   .RFCLK_CLOCK155                      ( GTM_LINF_REFCLK155 ),

   .AFE_RXD                             ( AFE_RXD_3 ),

   .OVSMP_OUT_DATA                      ( OVSMP_DATA_3[15:0] )
   ) ;



LINF_CLKRCV                             INST_LINF_CLKRCV_0(
   .LINF_RESET                          ( LINF_RESET ) ,
   .RFCLK_CLOCK155                      ( GTM_LINF_REFCLK155 ),
   .OVSMP_IN_DATA                       ( OVSMP_DATA_0[15:0] ),

   .RCV_OUT_DATA                        ( RCV_DATA_0[7:0] ),
   .RCV_OUT_DATA_EN                     ( RCV_DATA_EN_0 ),
 
   .GLBCF_LINF_MODE                     ( GLBCF_LINF_MODE[0] )
   );
LINF_CLKRCV                             INST_LINF_CLKRCV_1(
   .LINF_RESET                          ( LINF_RESET ) ,
   .RFCLK_CLOCK155                      ( GTM_LINF_REFCLK155 ) ,
   .OVSMP_IN_DATA                       ( OVSMP_DATA_1[15:0] ) ,

   .RCV_OUT_DATA                        ( RCV_DATA_1[7:0] ) ,
   .RCV_OUT_DATA_EN                     ( RCV_DATA_EN_1 ),

   .GLBCF_LINF_MODE                     ( GLBCF_LINF_MODE[1] )
   );
LINF_CLKRCV                             INST_LINF_CLKRCV_2(
   .LINF_RESET                          ( LINF_RESET ) ,
   .RFCLK_CLOCK155                      ( GTM_LINF_REFCLK155 ) ,
   .OVSMP_IN_DATA                       ( OVSMP_DATA_2[15:0] ) ,

   .RCV_OUT_DATA                        ( RCV_DATA_2[7:0] ) ,
   .RCV_OUT_DATA_EN                     ( RCV_DATA_EN_2 ),

   .GLBCF_LINF_MODE                     ( GLBCF_LINF_MODE[2] )
   );
LINF_CLKRCV                             INST_LINF_CLKRCV_3(
   .LINF_RESET                          ( LINF_RESET ) ,
   .RFCLK_CLOCK155                      ( GTM_LINF_REFCLK155 ) ,
   .OVSMP_IN_DATA                       ( OVSMP_DATA_3[15:0] ) ,

   .RCV_OUT_DATA                        ( RCV_DATA_3[7:0] ) ,
   .RCV_OUT_DATA_EN                     ( RCV_DATA_EN_3 ),

   .GLBCF_LINF_MODE                     ( GLBCF_LINF_MODE[3] )
   );

  assign LINF_OUT_RXD_0[7:0]        = RCV_DATA_0[7:0];
  assign LINF_OUT_RXDEN_0           = RCV_DATA_EN_0;

  assign LINF_OUT_RXD_1[7:0]        = RCV_DATA_1[7:0];
  assign LINF_OUT_RXDEN_1           = RCV_DATA_EN_1;

  assign LINF_OUT_RXD_2[7:0]        = RCV_DATA_2[7:0];
  assign LINF_OUT_RXDEN_2           = RCV_DATA_EN_2;

  assign LINF_OUT_RXD_3[7:0]        = RCV_DATA_3[7:0];
  assign LINF_OUT_RXDEN_3           = RCV_DATA_EN_3;



LINF_TX                                 INST_LINF_TX_0(
   .LINF_RESET                          ( LINF_RESET ),
   .GTM_SYSCLK77                        ( GTM_SYSCLK77 ),
   .GTM_SYSCLK311                       ( GTM_SYSCLK311 ),
   .GTM_SYSCLK155                       ( GTM_SYSCLK155 ),

   .LINF_TXD                            ( LINF_IN_TXD_0[7:0] ),
   .AFE_TXD                             ( AFE_TXD_0 )
   );
LINF_TX                                 INST_LINF_TX_1(
   .LINF_RESET                          ( LINF_RESET ),
   .GTM_SYSCLK77                        ( GTM_SYSCLK77 ),
   .GTM_SYSCLK311                       ( GTM_SYSCLK311 ),
   .GTM_SYSCLK155                       ( GTM_SYSCLK155 ),

   .LINF_TXD                            ( LINF_IN_TXD_1[7:0] ),
   .AFE_TXD                             ( AFE_TXD_1 )
   );
LINF_TX                                 INST_LINF_TX_2(
   .LINF_RESET                          ( LINF_RESET ),
   .GTM_SYSCLK77                        ( GTM_SYSCLK77 ),
   .GTM_SYSCLK311                       ( GTM_SYSCLK311 ),
   .GTM_SYSCLK155                       ( GTM_SYSCLK155 ),

   .LINF_TXD                            ( LINF_IN_TXD_2[7:0] ),
   .AFE_TXD                             ( AFE_TXD_2 )
   );
LINF_TX                                 INST_LINF_TX_3(
   .LINF_RESET                          ( LINF_RESET ),
   .GTM_SYSCLK77                        ( GTM_SYSCLK77 ),
   .GTM_SYSCLK311                       ( GTM_SYSCLK311 ),
   .GTM_SYSCLK155                       ( GTM_SYSCLK155 ),

   .LINF_TXD                            ( LINF_IN_TXD_3[7:0] ),
   .AFE_TXD                             ( AFE_TXD_3 )
   );




/*


LINF_RTM_PLL                            INST_LINF_RTM_PLL(
   .areset                              ( LINF_RESET ),
   .inclk0                              ( LINF_SYS_CLOCK155 ),
   .c0                                  ( LINF_RFCLK77 ),
   .locked                              (  ),
   );









LINF_RTM                                INST_LINF_RTM(
   .LINF_RESET                          ( LINF_RESET ),
   .LINF_RFCLK155                       ( RFCLK_CLOCK155 ),
   .LINF_RFCLK158                       ( LINF_RFCLK158 ),

   .RCV_IN_DATA                         ( RLDATA155M[7:0] ),
   .RCV_IN_DATA_EN                      ( RLDATAEN ),

   .RTM_OUT_CLK                         ( RTM_CLK ),
   .RTM_OUT_DATA                        ( RTM_DATA[7:0] )
    ) ;

wire[1:0]                       DELMT_FMCNT4;
wire[8:0]                       DELMT_FMCNT270;
wire[3:0]                       DELMT_FMCNT9;
wire[7:0]                       DELMT_DATA;
wire                            DELMT_DEN;

wire[7:0]                       RSCRM_OUT_DATA;
wire                            RSCRM_OUT_DEN;
wire[1:0]                       RSCRM_OUT_FMCNT4;
wire[8:0]                       RSCRM_OUT_FMCNT270;
wire[3:0]                       RSCRM_OUT_FMCNT9;

wire[7:0]                       FSM_DATA;
wire                            FSM_DEN;
wire[1:0]                       FSM_FRAME_CNT4;
wire[8:0]                       FSM_FRAME_CNT270;
wire[3:0]                       FSM_FRAME_CNT9;
wire[9:0]                       FSM_POINT;
wire                            FSM_POINT_EQUAL;
wire                            FSM_POINT_AIS;
wire                            FSM_POINT_ILLEGAL;
wire                            FSM_POINT_NDF;
wire                            FSM_POINT_INCREASE;
wire                            FSM_POINT_DECREASE;

wire[8:0]                       PLOAD_WADDR;
wire[8:0]                       PLOAD_WDATA;
wire                            PLOAD_WEN;

wire[4:0]                       RGEN_PL_T1;
wire[4:0]                       RGEN_PL_T2;
wire[4:0]                       RGEN_PL_T3;
wire[4:0]                       RGEN_PL_T4;

FRM4_DELMT                              INST_FRM4_DELMT(
   .FRM4_RESET                          ( LINF_RESET ),

   .FRM4_RXCLK                          ( RFCLK_CLOCK155 ),
   .LINF_IN_RXDATA                      ( RLDATA155M[7:0] ),
   .LINF_IN_RXDEN                       ( RLDATAEN ),

   .DELMT_OUT_FMCNT4                    ( DELMT_FMCNT4[1:0] ),
   .DELMT_OUT_FMCNT270                  ( DELMT_FMCNT270[8:0] ),
   .DELMT_OUT_FMCNT9                    ( DELMT_FMCNT9[3:0] ),
   .DELMT_OUT_DATA                      ( DELMT_DATA[7:0] ),
   .DELMT_OUT_DEN                       ( DELMT_DEN )
   );


FRM4_RSCRM                              INST_RSCRM(
   .FRM4_RESET                          ( LINF_RESET ),
   .FRM4_RXCLK                          ( RFCLK_CLOCK155 ),

   .DELMT_IN_FMCNT4                     ( DELMT_FMCNT4[1:0] ),
   .DELMT_IN_FMCNT270                   ( DELMT_FMCNT270[8:0] ),
   .DELMT_IN_FMCNT9                     ( DELMT_FMCNT9[3:0] ),
   .DELMT_IN_DATA                       ( DELMT_DATA[7:0] ),
   .DELMT_IN_DEN                        ( DELMT_DEN ),

   .RSCRM_OUT_DATA                      ( RSCRM_OUT_DATA[7:0] ),
   .RSCRM_OUT_DEN                       ( RSCRM_OUT_DEN ),
   .RSCRM_OUT_FMCNT4                    ( RSCRM_OUT_FMCNT4[1:0] ),
   .RSCRM_OUT_FMCNT270                  ( RSCRM_OUT_FMCNT270[8:0] ),
   .RSCRM_OUT_FMCNT9                    ( RSCRM_OUT_FMCNT9 ),
   .RSCRM_OUT_B1ERR                     (  ),
   .RSCRM_OUT_B1ERR_EN                  (  )
   );

reg[15:0]                               fpcnt;

always @( posedge LINF_RFCLK77 ) begin
   if ( fpcnt==16'd9719 )
      fpcnt                 <= 0;
   else
      fpcnt                 <= fpcnt +1;
end


aupp622                                  inst_aupp622(
   .reset                                ( LINF_RESET ),
   .clk_sys77m                           ( LINF_RFCLK77 ),
   .clk_lin155m                          ( RFCLK_CLOCK155 ),
   .en_77m                               ( RSCRM_OUT_DEN ),

   .fp_in                                ( RSCRM_OUT_FMCNT4==2'd0 && RSCRM_OUT_FMCNT270==9'd0 &&  RSCRM_OUT_FMCNT9==4'd0 ),
   .data_in                              ( RSCRM_OUT_DATA[7:0] ),
		
   .fp_pi_out                            (  ),
   .j1_pi_out                            (  ),
   .spe_pi_out                           (  ),
   .data_pi_out                          (  ),
		
   .fp_ppfa_regen                        ( fpcnt==0 ),
		
   .fp_pr_out                            (  ),
   .j1_pr_out                            (  ),
   .spe_pr_out                           (  ),
   .data_pr_out                          (  )
   );


AUPP4_FDETC                                        INST_AUPP4_FDETC(
   .AUPP4_RESET                                    ( LINF_RESET ),
   .AUPP4_RCLK                                     ( RFCLK_CLOCK155 ),

   .FDECT_IN_DEN                                   ( RSCRM_OUT_DEN ),
   .FDECT_IN_DATA                                  ( RSCRM_OUT_DATA ),
   .FDECT_IN_FMCNT4                                ( RSCRM_OUT_FMCNT4 ),
   .FDECT_IN_FMCNT270                              ( RSCRM_OUT_FMCNT270 ),
   .FDECT_IN_FMCNT9                                ( RSCRM_OUT_FMCNT9 ),

   .FDECT_OUT_DATA                                 ( FSM_DATA[7:0] ),
   .FDECT_OUT_DEN                                  ( FSM_DEN ),
   .FDECT_OUT_FMCNT4                               ( FSM_FRAME_CNT4[1:0] ),
   .FDECT_OUT_FMCNT270                             ( FSM_FRAME_CNT270[8:0] ),
   .FDECT_OUT_FMCNT9                               ( FSM_FRAME_CNT9[3:0] ),
   .FDECT_OUT_POINT                                ( FSM_POINT[9:0] ),
   .FDECT_OUT_POINT_EQUAL                          ( FSM_POINT_EQUAL ),
   .FDECT_OUT_POINT_AIS                            ( FSM_POINT_AIS ),
   .FDECT_OUT_POINT_ILLEGAL                        ( FSM_POINT_ILLEGAL ),
   .FDECT_OUT_POINT_NDF                            ( FSM_POINT_NDF ),
   .FDECT_OUT_POINT_INCREASE                       ( FSM_POINT_INCREASE ),
   .FDECT_OUT_POINT_DECREASE                       ( FSM_POINT_DECREASE )
   );

AUPP4_PI_FSM                                       INST_AUPP4_PI_FSM(
   .AUPP4_RESET                                    ( LINF_RESET ),
   .AUPP4_RCLK                                     ( RFCLK_CLOCK155 ),

   .FSM_IN_DATA                                    ( FSM_DATA[7:0] ),
   .FSM_IN_DEN                                     ( FSM_DEN ),
   .FSM_IN_FRAME_CNT4                              ( FSM_FRAME_CNT4[1:0] ),
   .FSM_IN_FRAME_CNT270                            ( FSM_FRAME_CNT270[8:0] ),
   .FSM_IN_FRAME_CNT9                              ( FSM_FRAME_CNT9[3:0] ),
   .FSM_IN_POINT                                   ( FSM_POINT[9:0] ),
   .FSM_IN_POINT_EQUAL                             ( FSM_POINT_EQUAL ),
   .FSM_IN_POINT_AIS                               ( FSM_POINT_AIS ),
   .FSM_IN_POINT_ILLEGAL                           ( FSM_POINT_ILLEGAL ),
   .FSM_IN_POINT_NDF                               ( FSM_POINT_NDF ),
   .FSM_IN_POINT_INCREASE                          ( FSM_POINT_INCREASE ),
   .FSM_IN_POINT_DECREASE                          ( FSM_POINT_DECREASE ),

   .FSM_OUT_DATA                                   (  ),
   .FSM_OUT_DEN                                    (  ),
   .FSM_OUT_SPE                                    (  ),
   .FSM_OUT_J1                                     (  ),
   .FSM_OUT_FRAME_CNT4                             (  ),
   .FSM_OUT_FRAME_CNT270                           (  ),
   .FSM_OUT_FRAME_CNT9                             (  ),

   .PLOAD_WADDR                                    ( PLOAD_WADDR[8:0] ),
   .PLOAD_WDATA                                    ( PLOAD_WDATA[8:0] ),
   .PLOAD_WEN                                      ( PLOAD_WEN ),

   
   .RGEN_ITPRE_ST1                                 (  ),
   .RGEN_ITPRE_ST2                                 (  ),
   .RGEN_ITPRE_ST3                                 (  ),
   .RGEN_ITPRE_ST4                                 (  ),
   .RGEN_PL_T1                                     ( RGEN_PL_T1[4:0] ),
   .RGEN_PL_T2                                     ( RGEN_PL_T2[4:0] ),
   .RGEN_PL_T3                                     ( RGEN_PL_T3[4:0] ),
   .RGEN_PL_T4                                     ( RGEN_PL_T4[4:0] )
   );

wire[8:0]              raddr_pl;
wire[8:0]              rdata_pl;
wire                   fp_to_pohp;
wire                   j1_to_pohp;
wire                   spe_to_pohp;
wire[7:0]              data_to_pohp;


pos_regen_au	U_pos_regen_au(
		.reset			(LINF_RESET),
		.clk_sys77m		(LINF_RFCLK77),

		.fp_ppfa_regen	(fpcnt==0),
		
		.pl_ais_force	(1'b0),
		.ptr_itpre_st1	( 2'd0 ),
		.ptr_itpre_st2	( 2'd0 ),
		.ptr_itpre_st3	( 2'd0 ),
		.ptr_itpre_st4	( 2'd0 ),
		.waddr_pl_h_t1	(RGEN_PL_T1),
		.waddr_pl_h_t2	(RGEN_PL_T2),
		.waddr_pl_h_t3	(RGEN_PL_T3),
		.waddr_pl_h_t4	(RGEN_PL_T4),
		.pi_chan_y3		( ),
		
		.raddr_pl		(raddr_pl),
		.rdata_pl		(rdata_pl),
		
		.fp_to_pohp		( fp_to_pohp ),
		.j1_to_pohp		( j1_to_pohp ),
		.spe_to_pohp	( spe_to_pohp ),
		.data_to_pohp	( data_to_pohp[7:0] ),
		.hp_fifo_ovf_1	( ),
		.hp_fifo_ovf_2	( ),
		.hp_fifo_ovf_3	( ),
		.hp_fifo_ovf_4	( ),
		.ptr_regen_st	( ),
		.h1_pos_y1		( )
		);


ram1kx9		U_ram1kx9(
		.wrclock		(RFCLK_CLOCK155),
		.wraddress		({1'b0,PLOAD_WADDR}),
		.data			(PLOAD_WDATA),
		.wren			(PLOAD_WEN),
		
		.rdclock		(LINF_RFCLK77),
		.rdaddress		({1'b0,raddr_pl}),
		.q				(rdata_pl)
		);

reg[1:0]                 cnt_4;
reg[8:0]                 cnt_261;
reg[8:0]                 cnt_270;
reg[3:0]                 cnt_9;
reg[3:0]                 cnt_fm9;
reg[7:0]                 b3_calcuting;
reg[7:0]                 b3_result;


always @( posedge LINF_RFCLK77 ) begin
   if ( fp_to_pohp==1'b1 )
      cnt_4                  <= 1;
   else
      cnt_4                  <= cnt_4 +1;
end

always @( posedge LINF_RFCLK77 ) begin
   if ( cnt_4==0 && j1_to_pohp==1'b1 && spe_to_pohp==1'b1)
      cnt_261                <= 1;
   else if ( cnt_4==0 && spe_to_pohp==1'b1) begin
      if ( cnt_261==260 )
         cnt_261             <= 0;
      else
         cnt_261             <= cnt_261 +1;
   end
end

always @( posedge LINF_RFCLK77 ) begin
   if ( fp_to_pohp==1'b1 )
      cnt_270                   <= 0;
   else if ( cnt_4==3) begin
      if ( cnt_270==269 )
         cnt_270                   <= 0;
      else
         cnt_270                   <= cnt_270 +1;
   end
end

always @( posedge LINF_RFCLK77 ) begin
   if ( fp_to_pohp==1'b1 )
      cnt_fm9                      <= 0;
   else if ( cnt_4==3 && cnt_270==269) begin
      if ( cnt_fm9==8 )
         cnt_fm9                   <= 0;
      else
         cnt_fm9                   <= cnt_fm9 +1;
   end
end


always @( posedge LINF_RFCLK77 ) begin
   if ( cnt_4==0 && j1_to_pohp==1'b1 && spe_to_pohp==1'b1)
      cnt_9                  <= 0;
   else if ( cnt_4==0 && spe_to_pohp==1'b1 && cnt_261==260 ) begin
      if ( cnt_9==8 )
         cnt_9               <= 0;
      else
         cnt_9               <= cnt_9 +1;
   end
end

always @( posedge LINF_RFCLK77 ) begin
   if ( cnt_4==0 && spe_to_pohp==1'b1 ) begin
      if ( cnt_261==260 && cnt_9==8 )
         b3_calcuting         <= 0;
      else
         b3_calcuting         <= b3_calcuting ^ data_to_pohp;
   end
end

always @( posedge LINF_RFCLK77 ) begin
   if ( cnt_4==0 && spe_to_pohp==1'b1 ) begin
      if ( cnt_261==260 && cnt_9==8 )
         b3_result            <= b3_calcuting ^ data_to_pohp;
   end
end

  
reg[7:0]                 b3_err_vector;
always @( cnt_4 or spe_to_pohp or cnt_261 or cnt_9 ) begin
   if ( cnt_4==0 && spe_to_pohp==1'b1 && cnt_261==0 && cnt_9==1 )
      b3_en                   <= 1'b1;
   else
      b3_en                   <= 1'b0;
end

always @(b3_result or data_to_pohp ) begin
   b3_err_vector              <= b3_result ^ data_to_pohp;
end



always @( posedge LINF_RESET or posedge LINF_RFCLK77) begin
   if ( LINF_RESET==1'b1 )
      b3_cnt                  <= 0;
   else if(b3_en==1'b1 )
      b3_cnt                  <= b3_cnt +b3_err_vector;
end







always @( posedge RFCLK_CLOCK155)  begin
        RDATA_PARREL[7:0]      <={ RLDATA155M[7] , RLDATA155M[6] , RLDATA155M[5] , RLDATA155M[4] , RLDATA155M[3] , RLDATA155M[2] , RLDATA155M[1] , RLDATA155M[0]} ;
        RDATA_EN               <=RLDATAEN ;
end

always @( posedge RFCLK_CLOCK155)  begin
    if ( RLDATAEN==1'b1 ) begin
        FPCHECK[63:8]     <=FPCHECK[55:0] ;
        FPCHECK[7:0]      <={ RLDATA155M[7] , RLDATA155M[6] , RLDATA155M[5] , RLDATA155M[4] , RLDATA155M[3] , RLDATA155M[2] , RLDATA155M[1] , RLDATA155M[0]} ;
    end
end


always @( posedge RFCLK_CLOCK155)  begin
    if ( FPCHECK[31:0]==32'hF6F6_2828 || FPCHECK[32:1]==32'hF6F6_2828 || FPCHECK[33:2]==32'hF6F6_2828 || FPCHECK[34:3]==32'hF6F6_2828 ||
         FPCHECK[35:4]==32'hF6F6_2828 || FPCHECK[36:5]==32'hF6F6_2828 || FPCHECK[37:6]==32'hF6F6_2828 || FPCHECK[38:7]==32'hF6F6_2828)
         A1A2FLAG_EN           <=1'b0 ;
    else
         A1A2FLAG_EN           <=1'b1 ;
end

   assign DEBUG_DEN        = RDATA_EN;
   assign DEBUG_DATA[7:0]  = RDATA_PARREL[7:0];
   assign DEBUG_A1A2FLAG   = A1A2FLAG_EN;




wire[7:0]                        TFRM_DATA;

wire[1:0]                        TB2_FMCNT4;
wire[8:0]                        TB2_FMCNT270;
wire[3:0]                        TB2_FMCNT9;
wire[7:0]                        TB2_DATA;



FRM4_TFRM                        INST_FRM4_TFRM(
   .FRM4_RESET                   ( LINF_RESET ),
   .FRM4_TXCLK                   ( LINF_RFCLK77 ),

   .TSOH_IN_FMCNT4               ( TB2_FMCNT4 ),
   .TSOH_IN_FMCNT270             ( TB2_FMCNT270 ),
   .TSOH_IN_FMCNT9               ( TB2_FMCNT9 ),
   .TSOH_IN_DATA                 ( TB2_DATA ),

   .TFRM_OUT_DATA                ( TFRM_DATA[7:0] )
   );

FRM4_TB2                         INST_FRM4_TB2(
   .FRM4_RESET                   ( LINF_RESET ),
   .FRM4_TXCLK                   ( LINF_RFCLK77 ),

   .TB2_IN_FMCNT4                ( cnt_4 ),
   .TB2_IN_FMCNT270              ( cnt_270 ),
   .TB2_IN_FMCNT9                ( cnt_fm9 ),
   .TB2_IN_DATA                  ( data_to_pohp ),

   .TB2_OUT_FMCNT4               ( TB2_FMCNT4 ),
   .TB2_OUT_FMCNT270             ( TB2_FMCNT270 ),
   .TB2_OUT_FMCNT9               ( TB2_FMCNT9 ),
   .TB2_OUT_DATA                 ( TB2_DATA )
   );

*/
endmodule

